<div class="member-main member-main2" id="J_DataTable">
	<div class="page-article" id="main">
		<div id="member_notify" class="member-notify">
		<{if $goods}>
		<form id="no-inventory-form" action="<{link app=b2c ctl=site_member act=to_confirm full=1}>" method="post">
		<input type="hidden" id="obj_id" name="obj_id" value="">
		<input type="hidden" id="opt" name="opt" value="all">
		<div class="member-mod">
			<table class="member-grid" style="text-align:center">
				<thead>
					<tr>
						<th><input type="checkbox" class="all-selector"  name="controllAll" id="controllAll" onclick="selectAll()"></th>
						<th><{t}>下单时间<{/t}></th>
						<th><{t}>货品编码<{/t}></th>
						<th><{t}>品牌<{/t}></th>
						<th><{t}>每包数量<{/t}></th>
						<th><{t}>数量<{/t}></th>
						<th><{t}>操作<{/t}></th>
					</tr>
				</thead>
				<tbody>
					<{foreach from=$goods item=items}>
					<tr ggid="<{$items.goods_id}>" class="ggid" rg_id="">
						<td rowspan="2"><input class="ck-grey" type="checkbox" name="is_checked[]" value="<{$items.obj_id}>"></td>
						<td rowspan="2"><{$items.createtime|cdate}></td>
						<td><!--<img src="<{$items.goods.image_default_id|storager:'s'}>"/>--><{$items.bn}></td>
						<td><{$items.goods.brand.brand_name}></td>
						<td><{$items.goods.unit_num}></td>
						<td><{$items.quantity}></td>
					</tr>
					<tr ggid="<{$items.goods_id}>">
						<td><{$items.price|cur_odr}></td>
						<td><{t}>确认数量：<{/t}></td>
						<td><{$items.has_confirm_num}></td>
						<td class="quantity">
							<{input type="text" vtype="required&&number" value=$items.quantity name="confirm_num[{$items.obj_id}]" id="confirm-{$items.obj_id}" style="width:14px;" onblur="check(this,{$items.quantity},{$items.obj_id})"}>
						</td>
						<td class="flg">
						<!--<a href="javascript:;" class="single_confirm" onclick="do_sbc_edit(this,'<{$items.obj_id}>')"><{t}>确认<{/t}></a>-->
						<button type="submit" class="single_confirm"  onclick="do_sbc_edit(this,'<{$items.obj_id}>')" rel="_request"><{t}>确认<{/t}></button>
						<a href="<{link app=b2c ctl='site_member' full='1' act='recommend' arg=$items.obj_id}>" class="recommend" rel="<{$items.goods.goods_id}>" rrid=""><{t}>推荐<{/t}></a><span></span>
						<input type="hidden" name="r_goods_id" value="" id="rnd"/></td>
					</tr>
					<{/foreach}>
				</tbody>
			</table>
		</div>
		<div style="text-align:right"  class="confirm-batch">
		<!--<button class="trigger-btn" rel="_request" style="background-color:gray;border:0;color:white;"><{t}>批量确认已选商品<{/t}></button>-->
			<input type="button" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:gray;border:0;color:white;" onclick="javascript:(0);">
		</div>
		</form>
		<{pagers data=$pager}>
		<{else}>
		<{t}>暂无商品<{/t}>
		<{/if}>
		</div>
	</div>
</div>
<script>
(function(){
	var _form = $('no-inventory-form');
})();

//没有选择商品时，按钮为灰色
$$('#no-inventory-form .ck-grey').addEvent('click',function(e){
	if(show().length == 0){
		no_checked();
	}else{
		has_checked();
	}
});

//选中商品的状态为黄色
function has_checked(){
	ul = '<button type="submit" class="trigger-btn"rel="_request" style="background-color:#f18007;border:0;color:white;"><{t}>批量确认已选商品<{/t}></button>';
	$$('#no-inventory-form .confirm-batch').set('html',ul);
}

//不选中时为灰色
function no_checked(){
	ul = '<input type="button" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:gray;border:0;color:white;" onclick="javascript:(0);">';
	$$('#no-inventory-form .confirm-batch').set('html',ul);
}

//获取选中商品
function show(){
	var cBox = document.getElementsByName("is_checked[]");
	var idents = new Array();
	for(i = 0;i < cBox.length;i++){
		if(cBox[i].checked){
			idents.push(cBox[i].checked);
		}
	}
	return idents;
}

function check(obj,quantity,obj_id){
    var gc_confirm_num = $$('#confirm-'+obj_id).get('value');

	if(isNaN(gc_confirm_num)){
	    alert("<{t}>请输入非负整数!<{/t}>");
		$$('#confirm-'+obj_id).set('value',quantity);
		return;
	}
	var reg = /^[1-9]\d*|0$/;
	var re = new RegExp(reg);
	if (re.test(gc_confirm_num) == null) {
		alert("<{t}>请输入正确的数量!<{/t}>");
		$$('#confirm-'+obj_id).set('value',quantity);
		return;
	} 

	if(gc_confirm_num < 0){
	    alert("<{t}>请输入非负整数!<{/t}>");
		$$('#confirm-'+obj_id).set('value',quantity);
		return;
	}
	if(gc_confirm_num > quantity){
		alert("<{t}>请输入非负整数的数量!<{/t}>");
		$$('#confirm-'+obj_id).set('value',quantity);
		return;
	}
}

function do_sbc_edit(e,obj_id){
	$('obj_id').set('value',obj_id);
	$('opt').set('value','single');
//    $('no-inventory-form').submit();
}

function selectAll(){
	var arr = document.getElementsByName("is_checked[]");
	var is_checked = arr[0].checked;
	for(var i = 0;i < arr.length;i++){
	    if(is_checked){
		    arr[i].checked = false;
		}else{
		    arr[i].checked = true;
		}
	}
	if(is_checked){
	    no_checked();
	}else{
		has_checked();
	}
}
</script>